<?php

namespace common\models;

use Yii;
use \common\models\base\Registration as BaseRegistration;

/**
 * This is the model class for table "registration".
 */
class Registration extends BaseRegistration
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return array_replace_recursive(parent::rules(),
	    [    
             

           [['code','forum','frm','arrival_time', 'departure_time', 'come_hotel', 'back_hotel', 'created_at', 'updated_at', 'deleted_at'], 'safe'],
            [['invitation_code', 'region', 'accompanied', 'dealer', 'dealer_code', 'post', 'name', 'genter', 'card_type', 'card_num', 'telephone', 'nationality', 'spare_contact', 'spare_contact_phone', 'come_transportation', 'departure_city', 'back_transportation', 'arrived_city', 'departure_location', 'back_flight_number', 'is_send', 'dietary_needs', 'is_ceremony', 'is_hotel'], 'string', 'max' => 50],
            [['email'], 'string', 'max' => 200],
            [['arrival_location'], 'string', 'max' => 45],
            [['come_flight_number', 'is_aircraft', 'created_by', 'updated_by', 'deleted_by'], 'string', 'max' => 32],
            [['status'], 'string', 'max' => 2]


           
        ]);
    }

    public function getInvitationCode()
    {
        return $this->hasOne(\common\models\InvitationCode::className(),['invitation_code'=>'invitation_code']);
    }

    public function getForums()
    {
        return $this->hasMany(\common\models\Forum::className(),['regis_id'=>'id']);
    }


    public function getAudience()
    {
        $aud = Character::findOne('db7ffa982bff11e888b400163e0509fe');
        return $aud->summitInformation;
    }

    protected $_auths = [];

    public function getAuths()
    {
        if (!$this->_auths){
            $this->_auths = $this->invitationCode?$this->invitationCode->auths:$this->getAudience();
        }
        return $this->_auths;
    }

    protected $_code;

    /**
     * @return mixed
     */
    public function getCode()
    {
        return $this->invitation_code;
    }

    /**
     * @param mixed $code
     */
    public function setCode($code)
    {
        $this->_code = $code;
        if ($code){
            $this->invitation_code = $code;
            $this->character = $this->invitationCode?$this->invitationCode->character->name:'';
        }
    }


    public static function findModel($code)
    {
        $model = null;
        $model=InvitationCode::verificationCode($code);
        // if ($code && InvitationCode::verificationCode($code)){
        //     $model = static::findOne(['invitation_code'=>$code]);
        //     //$model=invitationCode::findOne($code);
        //    // var_dump( $model);exit;
        // }

        // if (!$model){
        //     $model = new static();
        //     $model->code = $code;
        // }
        //var_dump($model);exit;
        return $model;
    }



    protected $_frm=[];

    public function getFrm()
    {
        $this->_frm = $this->forum?explode(',',$this->forum):[];
        return $this->_frm;
    }

    public function setFrm($value)
    {
        $this->forum = implode(',',$value);
        return $this->_frm = $value;
    }
	
	private $_label=[];
 
    public function getLabel() 
    { 	
		$this->_label = "'".$this->card_num;
		//$this->_label =$this->card_num;
        return $this->_label; 
    } 
 
    
	
	
	
	
	
	
	
	
	
	
}
